﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MvvMToolKitDemo.ViewModels
{
    public class UserViewModel : ObservableObject
    {
        public UserViewModel()
        {
            IncrementCounterCommand = new RelayCommand(IncrementCounter);
            DownloadTextCommand = new AsyncRelayCommand(DownloadTextAsync);
        }

        public IAsyncRelayCommand DownloadTextCommand { get; }

        private async Task<string> DownloadTextAsync()
        {
            await Task.Delay(3000); // Simulate a web request
            return "Hello world!";
        }

        private int counter;

        public int Counter
        {
            get => counter;
            private set => SetProperty(ref counter, value);
        }

        public ICommand IncrementCounterCommand { get; }

        private void IncrementCounter() => Counter++;
    }
}
